package cn.wolfcode.controller;

import cn.wolfcode.domain.Product;
import cn.wolfcode.service.IProductService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: 生产者(product)控制器类
 * @Author: 伍家钰
 * @Date: 2020/8/28 13:16
 * @Version: 1.0
 */
//@RestController
//@RequestMapping("products")
public class ProductController {
    @Autowired
    private IProductService productService;

    // 从注册中心中获取对应的端口
    @Value("${server.port}")
    private String port;

    @GetMapping("/get/{id}")
    private Object get(@PathVariable Long id) {
        System.out.println("调用了商品服务.....");
        Product product = productService.get(id);
        Product pp = new Product();
        BeanUtils.copyProperties(product, pp);
        pp.setName(product.getName() + "_" + port);
        return pp;
    }
}

